package com.hqj.service;

import com.hqj.dao.GetUserDao;
import com.hqj.dao.HomesDao;
import com.hqj.entity.Getuser;
import com.hqj.entity.Homes;
import com.hqj.util.ReturnValueUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
@Service
public class GetuserServiceI implements BaseService<Getuser> {

    @Autowired //按照类型注入
    private GetUserDao gd;
    @Autowired
    private HomesDao hd;

    @Override
    public List<Getuser> find(Getuser getuser) {
        List<Getuser> list = gd.find(getuser);
        /*for (Getuser g:list){
            String idcard = g.getIdcard();
            Homes h = new Homes();
            h.setUserIdcard(idcard);
            List<Homes> lis = hd.find(h);
            g.setList(lis);
        }*/
        return list;
    }

    @Override
    public Getuser get(Getuser getuser) {
        List<Getuser> list = this.find(getuser);
        getuser = list.size()>0?list.get(0):null;
        return getuser;
    }

    @Override
    public Map<String, Object> add(Getuser getuser) {
        if (getuser.getCreateDate()==null){
            getuser.setCreateDate(new Date());
        }
        int i = gd.add(getuser);
        return ReturnValueUtil.aer(i,"新增");
    }

    @Override
    public Map<String, Object> edit(Getuser getuser) {
        int i = gd.edit(getuser);
        return ReturnValueUtil.aer(i,"编辑");
    }

    @Override
    public Map<String, Object> remove(int id) {
        int i = gd.remove(id);
        return ReturnValueUtil.aer(i,"删除");
    }
}
